-
Notifications
You must be signed in to change notification settings - Fork 591
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(Overlay): overlay support SSR, close #4205 #4923
Conversation
8f6c856
to
5d65ef6
Compare
5d65ef6
to
f70ca80
Compare
components/overlay/popup.tsx
Outdated
@@ -111,7 +111,9 @@ class Popup extends Component<PopupProps, PopupState> { | |||
delay: 200, | |||
canCloseByTrigger: true, | |||
followTrigger: false, | |||
container: () => document.body, | |||
container: () => { | |||
if (typeof document !== 'undefined') return document.body; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里有必要加吗
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我理解是要的,因为在服务器端渲染(SSR)的过程中,React 组件的静态属性(如 static defaultProps)会在服务器端执行。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
执行的是函数声明,而不是函数本身的执行,函数本身不执行就没有问题。
f70ca80
to
3750dc9
Compare
components/overlay/overlay.tsx
Outdated
) { | ||
return; | ||
} | ||
if ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里去掉 document 了之后好像就没有拆成两个 if 的意义了
components/overlay/overlay.tsx
Outdated
@@ -622,7 +626,7 @@ class Overlay extends Component<OverlayV1Props, OverlayState> { | |||
const path = [] as Array<HTMLElement | Document | Window>; | |||
while (el) { | |||
path.push(el); | |||
if (el.tagName === 'HTML') { | |||
if (el.tagName === 'HTML' && typeof document !== 'undefined') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里感觉也没有必要,都不是 ssr 周期里的
3750dc9
to
d360cd4
Compare
No description provided.